package com.cheksin.controller;

import com.cheksin.excl.ExportXlsx;
import com.cheksin.excl.FileUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;

/**
 * @author 不愿透露
 * @Classname ExclReportController
 * @Description TODO
 * @Date 2021/12/9 11:48
 */
@Controller
public class ExclReportController {
    @PostMapping("/report")
    @ResponseBody
    public String exportXlsx(@RequestParam("file") MultipartFile file, String path) throws ParseException {
        path = (path == null || "".equals(path)) ? "D:\\" : path;
        String exportPath = path+"商品统计.xls";

        System.out.println(exportPath);
        String[] header = {"商品名称", "条码", "货号","规格", "单位", "新品", "商品分类", "现有库存", "销售数量", "商品总售价", "实收金额", "实收占比", "利润", "利润率", "商品品牌",
                "商品供应商"};
        try {
            //ExportXlsx.exportExcl(header,ExportXlsx.genGoods(FileUtil.multipartFileToFile(file)), exportPath);
        }catch (Exception e) {
            return e.toString();
        }

        /*List<Goods> goods = (List<Goods>) ExportXlsx.genGoods(readFile);
        List<Goods> copy = new ArrayList<>();
        List<String> name = ReadText.readFileContent("d:\\降价商品.txt");
        for (Goods good : goods) {
            if(name.indexOf(good.getMc()) > -1) {
                copy.add(good);
            }
        }
        ExportXlsx.exportExcl(header,copy, exportPath);*/
        return exportPath;
    }
}